﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BLL
{
    public class QuanHuyenBLL
    {
        public string MaQuanHuyen { get; set; }
        public string TenQuanHuyen { get; set; }

        LandEntities data = new LandEntities();
        public QuanHuyenBLL()
        {
           
        }

        public QuanHuyenBLL(string maQh, string tenQh)
        {
            this.MaQuanHuyen = maQh;
            this.TenQuanHuyen = tenQh;
        }

        public List<QuanHuyenBLL> DanhSachQuanHuyen(string maTinh)
        {
            var ds = from qh in data.QUAN_HUYEN
                     where qh.MATINHTP == maTinh
                     select new QuanHuyenBLL 
                     {
                         MaQuanHuyen = qh.MAQH,
                         TenQuanHuyen = qh.TENQH
                     };
            return ds.ToList<QuanHuyenBLL>();
        }

        public void ThemQuanHuyen(string maQH, string tenQH, string maTinh)
        {
            QUAN_HUYEN quanhuyen = new QUAN_HUYEN();
            quanhuyen.MAQH = maQH;
            quanhuyen.TENQH = tenQH;
            quanhuyen.MATINHTP = maTinh;
            data.QUAN_HUYEN.AddObject(quanhuyen);
            data.SaveChanges();
        }

        public void XoaQuanHuyen(string maQH)
        {
            QUAN_HUYEN quanhuyen = data.QUAN_HUYEN.Single(q => q.MAQH == maQH);
            data.DeleteObject(quanhuyen);
            data.SaveChanges();            
        }

        public void SuaQuanHuyen(string maQH, string tenQH)
        {
            QUAN_HUYEN quanhuyen = data.QUAN_HUYEN.Single(q => q.MAQH == maQH);
            quanhuyen.MAQH = maQH;
            quanhuyen.TENQH = tenQH;
            data.SaveChanges();
        }
    }
}
